<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>08-watch</title>
  </head>
  <body>
    <div id="app">
      {{ reversedMessage }}
      <hr>
      {{ user.fullName }}
    </div>

    <script src="../../dist/vue.js"></script>
    <script>
      const vm = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue',
          user: {
            firstName: '诸葛',
            lastName: '亮',
            fullName: ''
          }
        },
        computed: {
          reversedMessage: function() {
            return this.message.split('').reverse().join('')
          }
        },
        watch: {
          'user': {
            handler: function(newVal, oldVal) {
              this.user.fullName = this.user.firstName + ' ' + this.user.lastName
            },
            deep: true,
            immediate: true
          }
        }
      });
    </script>
  </body>
</html>
